package com.softdev.system.generator.util;

import com.softdev.system.generator.entity.ClassInfo;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


class TableParseUtilTest {
    @Test
    void test() {
        String columnLine = "`menu_name` varchar(50) not null [25]";
        System.out.println(columnLine);
        System.out.println(columnLine.matches("(.*?)"));
//         Pattern p = Pattern.compile("\\[([^\\]]+)\\]");
//        Matcher m = p.matcher(columnLine);
//        while (m.find()) {
//            System.out.println(m.group(1));
//        }

//        Pattern p = Pattern.compile("\\(.*?\\)");
        Pattern p = Pattern.compile("\\(\\(.*?\\)");
//         Pattern p = Pattern.compile("\\[([^\\]]+)\\]");
        Matcher m = p.matcher(columnLine);
        while (m.find()) {
            System.out.println(m.group(0));
            System.out.println(m.group(0));
        }

//        String str = "中华人民共和国，简称（中国）。";
//        Matcher mat = Pattern.compile("(?<=\\（)(\\S+)(?=\\）)").matcher(str);//此处是中文输入的（）
//        while (mat.find()) {
//            System.out.println(mat.group());
//        }

        String in = "(1000) Item(s): [item1.test],[item2.qa],[item3.production]";
        System.out.println("input string:"+ in);
        System.out.println("extract text inside  brackets:'()'");
         p = Pattern.compile("\\((.*?)\\)");
         m = p.matcher(in);

        while(m.find()) {
            System.out.println(m.group(1));
        }
        System.out.println("extract digital number inside  brackets:'()'");
        p = Pattern.compile("\\((\\d+)\\)");
        m = p.matcher(in);

        while (m.find()) {
            System.out.println(m.group(1));
        }


        System.out.println("extract text inside square brackets:'[]'");

        p = Pattern.compile("\\[(.*?)\\]");
        m = p.matcher(in);
        while (m.find()) {
            System.out.println(m.group(1));
        }
    }


//    @Test
//    void processTableIntoClassInfo() throws IOException {
//        String tableSql = "CREATE TABLE IF NOT EXISTS `gateway`.`authority_menu` (\n" +
//                "  `id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT 'id',\n" +
//                "  `authority_name` VARCHAR(50) NOT NULL,\n" +
//                "  `menu_id` BIGINT(20) NOT NULL,\n" +
//                "  `menu_name` VARCHAR(50) NOT NULL,\n" +
//                "  `permission` BINARY(16) NULL DEFAULT 0 COMMENT '角色权限：导入|导出|高级查询|详情|新增|删除|修改|查询，预留8位： 0000000011111111',\n" +
//                "  `created_by` VARCHAR(50) NULL,\n" +
//                "  `created_date` TIMESTAMP NULL DEFAULT NULL,\n" +
//                "  `last_modified_by` VARCHAR(50) NULL DEFAULT NULL,\n" +
//                "  `last_modified_date` TIMESTAMP NULL DEFAULT NULL,\n" +
//                "  PRIMARY KEY (`id`))\n" +
//                "ENGINE = InnoDB\n" +
//                "DEFAULT CHARACTER SET = utf8mb4";
//        ClassInfo classInfo = TableParseUtil.processTableIntoClassInfo(tableSql);
//        System.out.println(classInfo.getClassName());
//    }
}
